package com.flong.lambda;

import org.junit.Test;

import java.math.BigDecimal;

/**
 * @Author:liangjl
 * @Date: 2020/6/20-11:07
 * @Eamil:jilongliang@sina.com
 * @Description: 1、lambda表达式就是对接口的抽象方法重写
 * 2、lambda表达式简化了内部类代码的冗余
 */
public class Test1 {

    @Test
    public void test1() {

        //冗余
        //线程不调用start，是不会启动
        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("匿名内部类");
            }
        }).start();


        //使用lambda表达式进行
        new Thread(() -> System.out.println("匿名内部类")).start();

    }


    @Test
    public void test2() {
       /* goSwimming(new Swimmable() {
            @Override
            public void swimming() {
                System.out.println("我是匿名内部类游泳");
            }
        });*/

        goSwimming(() -> System.out.println("我是lambda游泳"));
    }


    @Test
    public void test3() {
        multiply(new Calculation() {
            @Override
            public int multiply(int a, int b) {
                return a * b;
            }
        });

        //使用lambda表达式
        multiply((a, b) -> {
            return a * b;
        });

    }


    public void goSwimming(Swimmable swimmable) {
        swimmable.swimming();
    }


    public void multiply(Calculation calculation) {
        int res = calculation.multiply(10, 8);
        System.out.println("10*8=" + res);
    }

}
